package com.yulan.Array;

import org.junit.Test;

import java.util.Arrays;
import java.util.LinkedList;

/**
 * 406. 根据身高重建队列
 */
public class LeetCode_406 {


    public int[][] reconstructQueue(int[][] people) {
        Arrays.sort(people ,(o1,o2) -> o1[0] == o2[0] ? o1[1] - o2[1] : o2[0] - o1[0]);//身高降序，人数升序

        LinkedList<int[] > list = new LinkedList<>();
        for(int[] i : people){
            System.out.print("["+i[0]+" "+i[1]+"] , ");
            list.add(i[1],i);
        }

        System.out.println();

        return list.toArray(new int[list.size()][2]);
    }

    @Test
    public void test(){
        int[][] matrix = {
                {7,0},
                {4,4},
                {7,1},
                {5,0},
                {6,1},
                {5,2},
        };

        for(int[] arr : reconstructQueue(matrix)){
            for(int num: arr){
                System.out.print(num+" ");
            }
            System.out.println();
        }
    }
}
